﻿using System.Windows;
using System.Windows.Controls;

namespace ReportingFramework
{
  public class Repeater : StackPanel
  {
    private double _heightThusFar = 0;

    public Repeater()
    {
    }

    public bool TryAdd(FrameworkElement control)
    {
      var heightRemaining = Height - _heightThusFar;
      control.Measure(new Size(Width, 1000));
      var shouldAdd = control.DesiredSize.Height + 20 <= heightRemaining;
      if (shouldAdd)
      {
        Children.Add(control);
        _heightThusFar += control.DesiredSize.Height;
      }
      return shouldAdd;
    }
  }
}
